<template>
    <div id="app">
      <h1>代理转发演示</h1>
      <div>
        <button @click="fetchRedirectedContent">获取百度内容</button>
      </div>
      <div id="content" v-html="content"></div>
    </div>
  </template>
  
  <script>
  export default {
    data() {
      return {
        content: "", // 用于存放从后端获取的代理内容
      };
    },
    methods: {
      // 调用后端接口获取目标 URL 内容
      async fetchRedirectedContent() {
        const targetUrl = "http://www.baidu.com"; // 目标 URL（你可以根据需求让用户选择）
        
        try {
          const response = await this.$axios.get(`http://your-server/proxy?targetUrl=${encodeURIComponent(targetUrl)}`);
          
          // 获取到的内容存储到 content 中
          this.content = response.data;
        } catch (error) {
          console.error("请求失败:", error);
          this.content = "请求失败，请稍后再试。";
        }
      },
    },
  };
  </script>
  
  <style scoped>
  #app {
    text-align: center;
  }
  
  button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
  }
  
  #content {
    margin-top: 20px;
    padding: 10px;
    border: 1px solid #ddd;
    min-height: 200px;
    background-color: #f9f9f9;
    overflow-y: auto;
  }
  </style>
  